Skip to content

Add model_fit_table() function to summarize endogenous calibration targets#1138

Open
jdebacker wants to merge 17 commits into
PSLmodels:masterfrom
jdebacker:calib_tables
Open

Add model_fit_table() function to summarize endogenous calibration targets#1138
jdebacker wants to merge 17 commits into
PSLmodels:masterfrom
jdebacker:calib_tables

Conversation

@jdebacker

Copy link
Copy Markdown
Member

Adds calib_table() to output_tables.py, which produces a 5-column table showing each calibrated parameter's name/symbol, value (or range), data target description, model moment, and data moment. Supports wealth Gini (beta_annual), investment rate I/K (delta_annual), and income Gini (e) as initial target types.

Adds calib_table() to output_tables.py, which produces a 5-column table
showing each calibrated parameter's name/symbol, value (or range),
data target description, model moment, and data moment. Supports wealth
Gini (beta_annual), investment rate I/K (delta_annual), and income Gini
(e) as initial target types.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov-commenter

codecov-commenter commented May 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 65.85366% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.26%. Comparing base (daeb53b) to head (7423fe7).
⚠️ Report is 9 commits behind head on master.

Files with missing lines Patch % Lines
ogcore/output_tables.py 67.53% 25 Missing ⚠️
ogcore/output_plots.py 25.00% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1138      +/-   ##
==========================================
- Coverage   73.34%   73.26%   -0.09%     
==========================================
  Files          21       21              
  Lines        5302     5394      +92     
==========================================
+ Hits         3889     3952      +63     
- Misses       1413     1442      +29     
Flag Coverage Δ
unittests 73.26% <65.85%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
ogcore/__init__.py 100.00% <100.00%> (ø)
ogcore/output_plots.py 88.13% <25.00%> (-0.56%) ⬇️
ogcore/output_tables.py 88.15% <67.53%> (-7.00%) ⬇️

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jdebacker jdebacker marked this pull request as ready for review June 11, 2026 19:25
@jdebacker jdebacker requested review from Copilot and rickecon June 11, 2026 19:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the project’s Python/tooling requirements to Python 3.12+, and adds new output functionality to summarize model-vs-data fit for selected moments, along with a small change to how lifecycle profile plots can overlay/normalize external data.

Changes:

  • Bump required Python version from >=3.11 to >=3.12 and update lockfile accordingly.
  • Add model_fit_table() to generate a grouped “Data vs Model” moments table from tpi_output and params.
  • Normalize plot_data in ss_profiles() (non-labor variables) to align the first point with the baseline profile.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 8 comments.

File Description
uv.lock Updates lock metadata for Python >=3.12 and reflects dependency/metadata adjustments.
pyproject.toml Raises requires-python to >=3.12 and adds a dev dependency group (ipykernel).
ogcore/output_tables.py Introduces model_fit_table() for reporting model fit moments vs. data targets.
ogcore/output_plots.py Adjusts ss_profiles() to normalize plotted data series (when provided) for better comparability.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ogcore/output_tables.py
Comment thread ogcore/output_tables.py Outdated
Comment thread ogcore/output_tables.py
Comment thread ogcore/output_tables.py
Comment thread ogcore/output_tables.py
Comment thread ogcore/output_tables.py Outdated
Comment thread ogcore/output_tables.py
Comment thread ogcore/output_plots.py Outdated
@jdebacker

Copy link
Copy Markdown
Member Author

Example of new table:

macro_moments = cm.get_macro_moments()
fiscal_moments = cm.get_fiscal_moments()
params.start_year = 2026
demog_moments = cm.get_demographic_moments(params)
inequality_moments = cm.get_inequality_moments()
target_moments = {
    **macro_moments,
    **fiscal_moments,
    **demog_moments,
    **inequality_moments,
}


# %%
# Call function and create table
calib_df = ot.model_fit_table(target_moments, params, tpi_vars)
print(calib_df)

produces:

                                              Moment   Data  Model
0                              Macroeconomic moments    NaN    NaN
1                            Investment rate $(I/K)$ 0.0380 0.0881
2                       Capital-Output ratio $(K/Y)$ 3.5628 3.1055
3                   Consumption-Output ratio $(C/Y)$ 0.6403 0.6850
4                               Savings rate $(B/Y)$ 0.2052 3.4496
5                                Interest rate $(r)$ 0.0458 0.0596
6                            Capital share of output 0.3833 0.8148
7                              Labor share of output 0.6167 0.6500
8                                     Fiscal moments    NaN    NaN
9                       Revenue to GDP ratio $(T/Y)$ 0.1179 0.1762
10            Gov't consumption to GDP ratio $(G/Y)$ 0.0491 0.0400
11        Pension outlays to GDP ratio $(Pension/Y)$ 0.0502 0.0632
12    Infrastructure spending to GDP ratio $(I_g/Y)$ 0.0359 0.0000
13                         Debt to GDP ratio $(D/Y)$ 0.9824 0.7800
14                            Distributional moments    NaN    NaN
15                          Gini coefficient, wealth 0.8456 0.5590
16                          Gini coefficient, income 0.6398 0.3793
17                Gini coefficient, after-tax income 0.4845 0.4411
18                               Demographic moments    NaN    NaN
19                                      Fraction 65+ 0.2407 0.2282
20                                   Pop growth rate 0.0086 0.0075

@jdebacker

Copy link
Copy Markdown
Member Author

With changes in OG-USA PR #150, together with the update to the plotting function in this PR, one can produce comparisons between lifecycle profiles between the model and data for savings, consumption, earnings, and hours worked that look like this one for assets:
assets

@jdebacker jdebacker changed the title Add calib_table function to summarize endogenous calibration targets Add model_fit_table() function to summarize endogenous calibration targets Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants